package com.example.logindemo.slice;

import com.example.logindemo.HelloWorldAbility;
import com.example.logindemo.MainAbility;
import com.example.logindemo.ResourceTable;
import com.example.logindemo.Test1Ability;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.window.dialog.ToastDialog;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {

    Text txt1 = null;
    Text txt2 = null;
    Button button = null;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        txt1 = (Text) findComponentById(ResourceTable.Id_Username);
        txt2 = findComponentById(ResourceTable.Id_password);
        button = findComponentById(ResourceTable.Id_btn1);
        button.setClickedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        new ToastDialog(this).setText("点击了登录按钮").setDuration(2000).show();
        Intent intent = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withAbilityName(Test1Ability.class.getName())
                .withBundleName(getBundleName())
                .build();

        intent.setOperation(operation);
        intent.setParam("username", "Admin");
        intent.setParam("password", "123456");
//        present(new Test1AbilitySlice(),intent);
        startAbility(intent);
    }
}
